#define _LED_MODULE_

#include "nuc970.h"
#include "sys.h"
#include "gpio.h"
#include "ledctr.h"
#include "pulse.h"
#include "dataproc.h"

const unsigned char  numtab[16]= {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E};

uint8_t LedBuff[4];
uint32_t LedCnt =0;

extern timer_pulse_type sys_pulse;
/*****************************************************************************//*!
*
* @brief   led task.
*
* @param   none
*
* @return  none
*
* @ Pass/ Fail criteria: none
*****************************************************************************/
void LedCtrTask(void const *argument)
{
    if(sys_pulse.bPulse_250ms)
    {
        LedCnt++;
        LedBuff[0]=numtab[(LedCnt>>12)&0x0F];
        LedBuff[1]=numtab[(LedCnt>>8)&0x0F];
        LedBuff[2]=numtab[(LedCnt>>4)&0x0F];
        LedBuff[3]=numtab[(LedCnt>>0)&0x0F];
    }
}

/*****************************************************************************//*!
*
* @brief   led init.
*
* @param   none
*
* @return  none
*
* @ Pass/ Fail criteria: none
*****************************************************************************/
void led_ctr_init(void)
{
    GPIO_Open(GPIOH, DIR_OUTPUT, PULL_UP);
}

/*****************************************************************************//*!
*
* @brief   led handle.
*
* @param   none
*
* @return  none
*
* @ Pass/ Fail criteria: none
*****************************************************************************/
void led_ctr_scan(void)
{
    static uint16_t i;
    uint32_t SegMsk;
    
    i++;
    i&=0x03;
    SegMsk = 0x0FUL& (~(1UL<<i));
    SegMsk <<= 12;
    
    outpw(REG_GPIOA_DATAOUT + GPIOH,(LedBuff[i]<<4) | SegMsk);
}


